<div class="easyui-layout" data-options="fit:true">
	<div data-options="region:'north',border:false">
		<form class="appForm">
			<div class="datagrid-toolbar">
				<table class="appTable">
					<tr>
						<td>
							<input name="Q_title_like" data-options="prompt:'标题'" class="easyui-textbox" type="text" style="width:100px;"/>
							<button type="submit" class="easyui-linkbutton" data-options="iconCls:'icon-search'">查询</button>
							<button type="button" onclick="$(this).parents('form').eq(0).form('reset');" class="easyui-linkbutton" data-options="iconCls:'icon icon-reset'">清空</button>
						</td>
					</tr>
				</table>
			</div>
		</form>
	</div>
	<div data-options="region:'center',border:false">
		<table class="appGrid"></table>
	</div>
</div>
<script type="text/javascript">
	var grids = $("table.appGrid");
	grids.eq(grids.size()-1).datagrid({
		id:'dg',
		url:_ctx+'/admin/article/list',
		sortName:'create_time',
		sortOrder:'desc',
		columns:[[
			{field:'id',checkbox:true},
			{field:'title',title:'标题',width:150,sortable:true,
				formatter: function(value,row,index){
					return '<a href="'+_ctx+'/blog/detail?id='+row.id+'" target="_blank">'+row.title+'</a>';
				}
			},
			{field:'user_name',title:'创建人',width:50,sortable:true},
			{field:'create_time',title:'创建时间',width:80,sortable:true,
				formatter: function(value,row,index){
					return value.format('yy-MM-dd hh:mm');
				}
			},
			{field:'edit_time',title:'修改时间',width:80,sortable:true,
				formatter: function(value,row,index){
					return value.format('yy-MM-dd hh:mm');
				}
			},
			{field:'status',title:'发布',width:30,
				formatter: function(val){
					return $.appDicFormat('status',val);
				}
			}
		]],
		appToolbar: [{
				iconCls: 'icon icon-edit',
				text:'修改',
				"key":'text_add',
				handler: function(){
					var grid = getDatagrid(this);
					var rows = grid.datagrid("getSelections");
					if(rows.length!=1){
						$.appAlert("请选择一行要编辑的记录！");
						return;
					}
					$("<div/>").dialog({
						title: '修改文章',
						href: _tpl+'/admin/article_add.tpl.php?uedit=1',
						maximized:true,
						remoteData:{
							url:_ctx+"/admin/article/get?id="+rows[0].id,
							success:function(datas){
								if(this.showProgress){
									$.messager.progress('close');
								}
								var form = $(this.dialog).find("form").eq(0);
								form.form('load',datas);
								//编辑器
								var editId = form.find("textarea:last").attr("id");
								if(editId){
									UE.delEditor(editId);
									var uedit = UE.getEditor(editId,{
										zIndex:9999
									});
									uedit.ready(function() {
										uedit.setContent(datas.detail);
									});
								}
								
								
								//获取标签
								$.appAjax({
									url:_ctx+"/admin/label/arts",
									data:{"article_id":datas.id},
									showProgress:false,
									success: function(json){
										var label = $("a#label_btn_1");
										var td = label.parent();
										$.each(json.data,function(i,r){
											if(td.find('a[labelId="'+r.id+'"]').size()==0){
												label.before('<a labelId="'+r.id+'" class="easyui-linkbutton l-btn l-btn-small" group="" id=""><input name="label_id[]" type="hidden" value="'+r.id+'"/><span class="l-btn-left"><span class="l-btn-text">&nbsp;'+r.name+'<span onclick="$(this).parents(\'a\').remove()">&nbsp;&nbsp;╳</span></span></span></a>&nbsp;');
											}
										});
									}
								});
							}
						},
						form:{},
						grid:grid.get(0)
					});
				}
			},'-',{
				iconCls: 'icon icon-delete',
				text:'删除',
				"key":'text_del',
				handler: function(){
					var grid = getDatagrid(this);
					var rows = grid.datagrid("getSelections");
					if(rows.length==0){
						$.appAlert("请选择要删除的记录！");
						return;
					}
					var ids = [];
					$.each(rows,function(i,r){
						ids.push(r.id);
					});
					$.appAjax({
						url:_ctx+"/admin/article/delete",
						data:{"Q_id_in":ids.join(',')},
						//以下为可选封装
						grid:grid.get(0),
						confirmTitle:'确认删除选择的记录？'
					});
				}	
		}]
	});
</script>